package com.lupus.persistence.sql;

import java.util.*;

public class SqlGenerator {
	private static Map<String,SqlGenerator> generatorCacheMap = new HashMap<String,SqlGenerator>();
	public static SqlGenerator getSqlGenerator(){
		String databaseType = "mysql";
		return getSqlGenerator(databaseType);
	}
	
	public static SqlGenerator getSqlGenerator(String databaseType){
		SqlGenerator sqlGenerator = null;
		if(!generatorCacheMap.containsKey(databaseType)){
			if("oracle".equalsIgnoreCase(databaseType)){
				sqlGenerator = new OracleSqlGenerator();
			}else if ("sqlserver".equalsIgnoreCase(databaseType)){
				sqlGenerator = new SqlserverSqlGenerator();
			}else if("mysql".equalsIgnoreCase(databaseType)){
				sqlGenerator = new MysqlSqlGenerator();
			}else{
				sqlGenerator = new SqlGenerator();
			}
			generatorCacheMap.put(databaseType,sqlGenerator);
		}else{
			sqlGenerator = generatorCacheMap.get(databaseType);
		}
		return sqlGenerator;
	}
	
	public String createSql(Map map){
		String action = (String)map.get("action");
		String sql = null;
		if("insert".equalsIgnoreCase(action)){
			sql = createInsertSql(map);
		}else if("update".equalsIgnoreCase(action)){
			sql = createUpdateSql(map);
		}else if("delete".equalsIgnoreCase(action)){
			sql = createDeleteSql(map);
		}else if("query".equalsIgnoreCase(action)){
			sql = createQuerySql(map);
		}
		System.out.println("generate sql is----:"+sql);
		return sql;
	}
	protected String createInsertSql(Map map){
		return null;
	}
	
	protected String createUpdateSql(Map map){
		return null;
	}
	
	protected String createQuerySql(Map map){
		return null;
	}
	
	protected String createDeleteSql(Map map){
		return null;
	}
}
